package com.css.zfzx.sjcj.modules.yhdisaster.viewobjects;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: zdyh_sjpg
 * @Author: lhl
 * @CreateDate: 2022/4/19 15:05
 */
public class QueueVO {
    private int maxsize;//最大容量
    private int front;//队列头
    private int rear;//队列尾
    private List<Integer> list;//数组存储数据，模拟队列

    //创建队列的构造函数
    public QueueVO(int maxsize) {
        this.maxsize = maxsize;
        this.front = -1;//指向队列头，分析出front是指向队列头的前一个位置
        this.rear = -1;//指向队列尾，指向队列尾的数据也是指向数组的最后一个数据
        this.list = new ArrayList<>(maxsize);
    }

    //判断队列是否为空队列
    public boolean isEmpty() {
        return front == rear;
    }

    //判断队列是否为满队列
    public boolean isFull() {
        return rear == maxsize - 1;
    }

    //入队列
    public void addQueue(int data) {
        //判断队列是否为满队列
        if (isFull()) {
            System.out.println("队列满，无法加入队列");
            return;
        }
        rear++;
        list.add(data);
    }

    //展示队列
    public void showQueue() {
        //判断队列是否为空队列
        if (isEmpty()) {
            System.out.println("空队列，无数据");
            return;
        }
        for (int i = 0; i < list.size(); i++) {
            System.out.printf("arr[%d]=%d\n", i, list.get(i));
        }
    }

    //出队列
    public void removeQueue() {
        //判断队列是否为空队列
        if (isEmpty()) {
            System.out.println("空队列，无操作数据");
            return;
        }
        list.remove(0);
    }
}
